package com.xxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xxx.mapper.EmployeeMapper;
import com.xxx.pojo.ClassInfo;
import com.xxx.pojo.Employee;
import com.xxx.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper mapper;


    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public IPage getByPage(IPage page,String name) {
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        lqw.like(null != name && !"".equals(name.trim()),Employee::getName,name);
        lqw.orderByDesc(Employee::getUpdateTime);
        IPage iPage = mapper.selectPage(page, lqw);

        return iPage;
    }

    @Override
    public Employee okLogin(String username) {
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        Employee employee = null;
        if(null != username && !username.trim().equals("")){
            lqw.eq(Employee::getUsername,username).eq(Employee::getStatus,1);
            employee = mapper.selectOne(lqw);
        }
        return employee;
    }

    /**
     * 添加员工
     * @param employee
     * @return
     */
    @Override
    public int save(Employee employee) {
        int insert = mapper.insert(employee);
        return insert;
    }

    @Override
    public int modifyStatus(Employee employee) {

        LambdaQueryWrapper<ClassInfo> lqw = new LambdaQueryWrapper<>();


        int update = mapper.updateById(employee);
        return update;

    }


}
